import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:series_play/generated/assets.dart';
import 'package:series_play/pages/home/home_category_page.dart';
import 'package:series_play/pages/home/home_for_you_page.dart';
import 'package:series_play/pages/home/home_latest_page.dart';
import 'package:series_play/pages/home/home_rank_page.dart';
import 'package:series_play/widget/app_tab.dart';
import 'package:series_play/utils/jump_helper.dart';
import 'package:series_play/widget/app_color.dart';
import 'package:series_play/widget/app_image.dart';
import 'package:series_play/widget/app_text.dart';
import '../../comm/base/base_state.dart';
import 'controller/home_controller.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends BaseControllerState<HomePage, HomeController>
    with TickerProviderStateMixin {
  final tabs = ['推荐', '最新', '排行', '分类'];
  late TabController _tabController;
  final _childPages = <Widget>[
    HomeForYouPage(),
    HomeLatestPage(),
    HomeRankPage(),
    HomeCategoryPage(),
  ];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  Widget buildPage(BuildContext context) {
    // 搜索
    final searchView = Padding(
      padding: const EdgeInsets.all(18).w,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Expanded(
            child: GestureDetector(
              onTap: (){
                JumpHelper.search();
              },
              child: Container(
                padding: const EdgeInsets.symmetric(horizontal: 12).w,
                height: 34.w,
                decoration: BoxDecoration(
                  color: AppColor.white_20,
                  borderRadius: BorderRadius.circular(4).r,
                ),
                alignment: Alignment.centerLeft,
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    AppImage(Assets.imagesIcSearch, size: 18),
                    8.horizontalSpace,
                    AppText.secondary('新手专属任务'),
                  ],
                ),
              ),
            ),
          ),
          10.horizontalSpace,
          Container(
            alignment: Alignment.center,
            width: 36.w,
            height: 36.w,
            child: Stack(
              children: [
                Positioned(
                  left: 0,
                  bottom: 0,
                  right: 0,
                  child: AppImage(
                    Assets.imagesIcHomeVip,
                    width: 28,
                    height: 28,
                  ),
                ),
                Positioned(
                  left: 0,
                  top: 0,
                  right: 0,
                  child: Container(
                    decoration: BoxDecoration(
                      color: const Color(0xffF6C725),
                      borderRadius: BorderRadius.circular(8).r,
                    ),
                    height: 14.w,
                    alignment: Alignment.center,
                    child: AppText(
                      '50%',
                      color: const Color(0xff670426),
                      fontSize: 10,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );

    return Column(
      children: [
        searchView,
        Container(
          height: 35.w,
          padding: const EdgeInsets.symmetric(horizontal: 16).w,
          child: AppTab(tabs, _tabController,),
        ),
        10.verticalSpace,
        Expanded(
          child: TabBarView(
            controller: _tabController,
            children: _childPages,
          ),
        ),
      ],
    );
  }

  @override
  HomeController createController() {
    return HomeController();
  }

  @override
  bool hideAppbar() {
    return true;
  }

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
  }

  @override
  bool showDefaultBackground() {
    return true;
  }
}
